home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * frommidi.c: Functions for reading patch data from the MIDI stream.
- * A part of OberSuite for the Commodore Amiga.
- *
- * Author: Daniel Barrett, barrett@cs.umass.edu.
- * Version: 1.0.
- * Copyright: None! This program is in the Public Domain.
- * Please share it with others.
- ***************************************************************************/
-
- #include "decl.h"
-
- /*
- * Request one or more patches from the MIDI stream, and store them in the
- * supplied PATCHINFO structure. Return TRUE on success (else FALSE).
- * If a data transfer fails, retry the transfer up to NUM_RETRIES times.
- * Possible things that can go wrong:
- *
- * The user could press ^C.
- * A transfer could fail NUM_RETRIES times or more.
- */
-
- BOOL GetPatchFromMidi(PATCHINFO *pi)
- {
- int patchesGotten = 0; /* How many patches have arrived safely? */
- int numTries = 0; /* How many times have we retried 1 patch? */
- long offset = 0L; /* Where in the patch data are we? */
-
- ResetSerialPort();
- while ((patchesGotten < pi->numPatches) && (numTries < NUM_RETRIES))
- {
-
- /* Did the user press ^C? */
-
- if (CtrlcCheck())
- {
- ErrorMsg(ERROR_CTRLC);
- return(FALSE);
- }
-
- /* Request and obtain the data for 1 patch. */
-
- RequestTheRightPatch(pi, patchesGotten);
- pi->actualSize = GetFromMidi(pi, offset);
-
- /* If the user pressed ^C during the transfer, goodbye! */
-
- if (pi->actualSize == CTRL_C_NO_BYTES)
- {
- ErrorMsg(ERROR_CTRLC);
- return(FALSE);
- }
-
- /* If the patch data is OK, tell the user, and get ready to obtain
- * the next patch. */
-
- else if (VerifyPatch(pi, offset))
- {
- patchesGotten++;
- if (OUTPUT_ALLOWED)
- PrintPatchInfo(pi, offset);
- numTries = 0;
- offset += pi->rightSize;
- }
-
- /* The patch data is not OK. If we haven't done too many retries yet,
- * try again. */
-
- else if (++numTries < NUM_RETRIES)
- {
- if (ERR_OUTPUT_ALLOWED)
- fprintf(stderr, " <%d> Retry #%d...\n",
- patchesGotten, numTries);
- ResetSerialPort();
- }
- }
-
- /* Did we successfully get the data in fewer than NUM_RETRIES attempts? */
-
- return((BOOL)(numTries < NUM_RETRIES));
- }
-
-
- /*
- * Get one patch from MIDI. Return the number of bytes read, or
- * CTRL_C_NO_BYTES if the user pressed ^C during the transfer.
- */
-
- long GetFromMidi(PATCHINFO *pi, long offset)
- {
- PrepareToReadMidi(pi->data + offset, pi->rightSize);
- return(DoTheIO());
- }
-
-
- /*
- * Request 1 patch from the synth.
- * If the user has requested ALL patches, use their original patch numbers.
- * Otherwise, use the new patch number that the user specified on the
- * command line.
- */
-
- void RequestTheRightPatch(PATCHINFO *pi, int relativeNum)
- {
- if (pi->patchNum == ALL_PATCHES_NUM)
- RequestOnePatch(relativeNum, pi->mode);
- else
- RequestOnePatch(pi->patchNum, pi->mode);
- }
-